package com.xpgk.mvc.ddc.bgdj.gd;


import java.text.SimpleDateFormat;
import java.util.Date;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.ddc.entity.Business;
import com.xpgk.mvc.ddc.entity.Owner;
import com.xpgk.mvc.ddc.entity.Plate;
import com.xpgk.mvc.ddc.entity.Vehicle;
import com.xpgk.mvc.ddc.entity.VehicleParemeters;
import com.xpgk.mvc.ddc.statistic.DailyStasticService;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.user.User;

public class BgdjGdController  extends  BaseController{
	private DailyStasticService dailyStasticService;
	
	public void index() {
		if(!getCUserOrganIds().equals("f73bfba518ff4048afbdc006e3eda906")){
			setAttr("orgid", getCUserOrganIds());
		}
		render("gdlist.html");
	}
	
	public  void  getlist(){
		String json = paging(splitPage, Business.sqlId_splitPageSelect,Business.sqlId_splitPageFrom);
		renderJson(json);
	}
	
	public  void  details(){
		ids=getPara("ids");
		Business business = Business.dao.findById(ids);
		setAttr("business", business);
		setAttr("owner", Owner.dao.findById(business.get("NEWOWNERIDS")));
		setAttr("vehicleparemeters", VehicleParemeters.dao.findById(business.get("NEWPAREMETERSIDS")));
		setAttr("vehicleparemeters2", VehicleParemeters.dao.findById(business.get("OLDPAREMETERSIDS")));
		setAttr("plate", Plate.dao.findById(business.get("NEWPLATEIDS")));
		setAttr("vehicle", Vehicle.dao.findById(business.get("VEHICLEIDS")));
		render("details.html");
	}

	@Before(Tx.class)
	public  void  togd(){
		User user = getCUser();
		String jbrids = user.getStr(User.column_ids);
		String jbr = user.getStr(User.column_name);
		String organids = user.getStr(User.column_organizationids);
		Organization organization = Organization.dao.findById(organids);
		String organ = organization.getStr(Organization.column_name);
		String ids = getPara("ids");
		SimpleDateFormat  sdf = new SimpleDateFormat("yyyy-MM-dd");
		Business business = Business.dao.findById(ids);
		business.set(Business.column_GDDATE, sdf.format(new Date()));
		business.set(Business.column_GDJBRIDS, jbrids);
		business.set(Business.column_GDJBR, jbr);
		business.set(Business.column_STATUS,"4");
		Vehicle vehicle = Vehicle.dao.findById(business.get("VEHICLEIDS"));
		vehicle.set(Vehicle.column_BUSINESSTYPE,"0");
		boolean result = vehicle.update();
		result = business.update();
		result = dailyStasticService.saveDailyStastic(organids,organ,sdf.format(new Date()),"3","4");
		renderJson(result);
	}
	
}
